import { QueryInterface } from "sequelize/types";

// 更新数据库
module.exports = {
  up: async (queryInterface: QueryInterface) => {
    await queryInterface.sequelize.query(`
      CREATE TABLE
      'User' (
        'id' int unsigned NOT NULL AUTO_INCREMENT,
        'uuid' char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
        'name' char(64) NOT NULL DEFAULT '',
        'nickname' varchar(255) DEFAULT NULL,
        'email' char(100) DEFAULT NULL,
        'salt' char(16) NOT NULL DEFAULT '',
        'password' varchar(255) NOT NULL DEFAULT 'NOPASSWORD',
        'phone' char(20) DEFAULT NULL,
        'avatar' varchar(200) DEFAULT NULL,
        'registerIP' char(40) DEFAULT NULL,
        'createdAt' datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
        'updatedAt' datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
        'deletedAt' datetime DEFAULT NULL,
        PRIMARY KEY ('id'),
        UNIQUE KEY 'uuid' ('uuid'),
        UNIQUE KEY 'name' ('name'),
        UNIQUE KEY 'email' ('email'),
        UNIQUE KEY 'phone' ('phone')
      ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
    `);

    // 添加测试用户，在自己环境正式使用时，可以删除
    await queryInterface.sequelize.query(`
      insert into User(uuid, name, salt) values
      ('uuid-12345678', '测试用户', '678456');
    `);
  }

  // down: async (queryInterface: QueryInterface) => {
  //   // todo
  // },
};
